package request

import (
	"github.com/astaxie/beego/validation"
	"strings"
)

type AttachmentRequest struct {
	AttId uint   `json:"attId"` //主键
	Name  string `json:"name"`  //附件名称
}

func (s *AttachmentRequest) Valid(v *validation.Validation) {
	if s.AttId <= 0 {
		v.SetError("AttId", "图片Id不合法")
	} else if s.Name == "" {
		v.SetError("Name", "附件名称不能为空")
	} else if strings.IndexAny(s.Name, "/") > -1 || strings.IndexAny(s.Name, "\\") > -1 {
		v.SetError("Name", "附件名称不能包含/、\\等字符")
	}
}

type AttachmentMoveRequest struct {
	Images string `json:"images" binding:"required"` //图片ID
	Pid    uint   `json:"pid" binding:"required"`    //更新到新的分类 ,分割
}

func (c *AttachmentMoveRequest) Valid(v *validation.Validation) {
	if len(c.Images) == 0 {
		v.SetError("Images", "没有可选项")
	}
}

type AttachmentBatchRequest struct {
	AttIds []uint `json:"attIds" binding:"required"` //主键集合 必填
}

func (c *AttachmentBatchRequest) Valid(v *validation.Validation) {
	if len(c.AttIds) == 0 {
		v.SetError("AttIds", "没有可选项")
	}
}

type FileChunkRequest struct {
	ChunkNumber     uint   `form:"chunkNumber"`
	ChunkSize       uint   `form:"chunkSize"`
	ActualChunkSize uint   `form:"actualChunkSize"`
	TotalSize       uint   `form:"totalSize"`
	Filename        string `form:"filename"`
	TotalChunks     uint   `form:"totalChunks"`
	Hash            string `form:"hash"`
	UniqAt          string `form:"uniqAt"`
}

func (c *FileChunkRequest) Valid(v *validation.Validation) {
	if c.ChunkNumber <= 0 {
		v.SetError("ChunkNumber", "没有可选项")
	} else if c.ChunkSize <= 0 {
		v.SetError("ChunkSize", "没有可选项")
	} else if c.TotalSize <= 0 {
		v.SetError("TotalSize", "没有可选项")
	} else if c.Hash == "" {
		v.SetError("Hash", "不能为空")
	} else if c.UniqAt == "" {
		v.SetError("UniqAt", "缺少上传时间")
	}
}
